package com.liu.netty.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Base64;

/**
 * 图片解码工具
 * 图片压缩工具
 */
public class ImageUtils {



     public static boolean base64DecodeImage(String imgStr,String path,String pathName,boolean flage){

         File filepath = new File(path);
         System.out.println("图片路径：" + path);
         if (!filepath.exists()) {
             filepath.mkdirs();
         }
         if (imgStr == null || imgStr.equals("")) {
             return false;
         }
         if (path == null || path.equals("")) {
             return false;
         }
         OutputStream out = null;
         try{
         byte[] b = Base64.getDecoder().decode(imgStr);
         for(int i = 0 ;i<b.length;i++){
             if (b[i]<0){
                 b[i]+=256;
             }
         }
           out = new FileOutputStream(pathName);

         out.write(b);
            out.flush();
        }catch (Exception e){

             return  false;

        }finally {
             try {
                 out.close();
             } catch (IOException e) {
                 e.printStackTrace();
             }
         }




         return  true;

     }



}
